<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    //登录页
    public function show()
    {
        return view('home.login');
    }

    //登录
    public function sign(Request $request)
    {

        $token=Auth::guard('admin')->attempt(['name'=>$request->name,'password'=>$request->password]);

        if($token) {

//            $user = Auth::guard('web')->user();
            $user = Auth::guard('admin')->user();//admin

            session()->flash('success', '欢迎回来');
            return response()->json($user);
        }

        //登录失败，没有此用户
        return response()->json($token);
    }

    //退出登录
    public function logout()
    {
        $logout =  Auth::guard('admin')->logout();

        return redirect()->route('admin.login.show');
    }
}
